﻿#include "PyFITKMaterialsBase.h"
#include "FITKAcousticsPhysics.h"
#include "FITKAcousticsAbsMaterial.h"

Acoustics::PyFITKMaterialsBase::PyFITKMaterialsBase(const QString & name)
{
    //获取材料管理器
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return;
    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    if (matMgr == nullptr) return;
    //获取对象
    Interface::FITKAbstractMaterial* material = matMgr->getDataByName(name);
    if (!material)return;
    _material = material;
}

QString Acoustics::PyFITKMaterialsBase::getName()
{
    if (_material)
        return _material->getDataObjectName();
    return QString();
}

bool Acoustics::PyFITKMaterialsBase::setName(const QString & name)
{
    //空字符直接返回
    if (name == "" || !_material)return false;
    //获取材料管理器
    Acoustics::FITKAcousticsPhysics* phy = Acoustics::FITKAcousticsPhysics::GetAcousticsPhysicsFromFrame();
    if (phy == nullptr) return false;
    Acoustics::FITKAcousticsMaterialManager* matMgr = phy->getMaterialManager();
    if (matMgr == nullptr) return false;

    //获取名称-查重处理
    if (matMgr->getDataByName(name) && _material->getDataObjectName() != name)return false;

    _material->setDataObjectName(name);
    return true;
}
